package com.heihei.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.heihei.common.tree.INode;
import com.heihei.entity.HelloWorldEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel("HelloWorld 树结构测试VO")
public class HelloWorldTreeVO extends HelloWorldEntity implements INode<HelloWorldTreeVO> {

    /**
     * 父节点ID
     */
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "父节点ID")
    private Long parentId;

    /**
     * 子孙节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    @ApiModelProperty(value = "子孙节点")
    private List<HelloWorldTreeVO> children;

    private Boolean hasChildren;

    /**
     * 上级名称
     */
    @ApiModelProperty(value = "上级名称")
    private String parentName;

    @Override
    public List<HelloWorldTreeVO> getChildren() {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        return this.children;
    }
}